

$(function(){
    localStorage.removeItem('color');
    localStorage.removeItem('fontSize');
    localStorage.removeItem('lineHeight');
    localStorage.removeItem('black');
    localStorage.removeItem('tips');
if(!localStorage.a_tips){
    $("body").append('<div class="start-opacity"><span></span></div>')
}
localStorage.a_tips = 1;
if(localStorage.a_color||localStorage.a_fontSize||localStorage.a_lineHeight||localStorage.a_black){
    var bgcolor = JSON.parse(localStorage.getItem("a_color"));
    var newFontSize = JSON.parse(localStorage.getItem("a_fontSize"));
    var newLineHeight = JSON.parse(localStorage.getItem("a_lineHeight"));
    var newBlack = JSON.parse(localStorage.getItem("a_black"));
    if(bgcolor==null){

    }else{
        $("#setting").attr("data-localColor",bgcolor);
    }

    if(newBlack==null){

    }else{
        $("#mulu-btn").attr("data-black",newBlack);
    }

    if(bgcolor=="R7"){
        $("#night-btn").addClass("check")
    }
    checkColor();
    $("#text").css("font-size",newFontSize);
    $("#text p").css("line-height",newLineHeight);
    var module = $(".set-fontsi a");
    for(var i= 0;i<module.length;i++ ){
        var moduleColor = module.eq(i).attr("data-color");
        if(bgcolor=="R7"){
            module.eq(0).addClass("red-circle").siblings().removeClass("red-circle")
        }
        if(moduleColor == bgcolor){
            module.eq(i).addClass("red-circle").siblings().removeClass("red-circle")
        }
    }
    var line = $(".set-linehi a");
    for(var j= 0;j<line.length;j++ ){
        var lineHi = line.eq(j).css("line-height");
        if(lineHi == newLineHeight ){
            line.eq(j).addClass("red-line").siblings().removeClass("red-line")
        }
    }
}

$(".start-opacity").on("click",function() {
    $(".start-opacity").animate({top:-2000},500,'swing');
});
$(".other").on('click',function() {
    if($(this).siblings(".other-list").css("display")=="none"){
        $(".other-list").css("display","block");
    }else {
        $(".other-list").css("display","none");
    }

});
$("#set-btn").on('click',function() {
    if($(".setting").css("display")=="none"){
        $(".setting").css("display","block");
    }else {
        $(".setting").css("display","none");
    }

});
$("#night-btn").on('click',function() {
    var saveColor = $("#setting").attr("data-localColor");
    var saveBlack =  $("#mulu-btn").attr("data-black");
    if($(this).hasClass("check")&&saveColor=="R7"){
        $("#setting").attr("data-localColor",saveBlack);
        checkColor();

        $(this).removeClass("check");
    }else{
        $(".list-catalog").css("background-color","#1b1b1b");
        $(".fixed-head").css("background-color","#1b1b1b");
        $(".list-catalog").css("color","#d5d5d5");
        $(".triangle").css("border-bottom-color","#1b1b1b");
        $("body").css("background-color","#1b1b1b");
        $("#top").css("color","#d5d5d5");
        $("#setting").attr("data-localColor","R7");
        $(this).addClass("check");
    }
    var color = $("#setting").attr("data-localColor");
    localStorage.a_color =JSON.stringify(color);
});
$("#top").on("tap",function(){
    if($(this).hasClass("bg-opacity")){
        $(".read-head").animate({top:-2000},200,'swing');
        $(".read-foot").animate({bottom:-2000},200,'swing');
        $(".setting").css("display","none");
        $(".other-list").css("display","none");
        $(this).removeClass("bg-opacity");
    }else{
        $(".read-head").animate({top:0},200,'swing');
        $(".read-foot").animate({bottom:0},200,'swing');
//		$(".triangle").css("border-bottom","15px solid #fafafa");
        $(this).addClass("bg-opacity");
    }
});

$(".set-fontsi a").on("click",function() {
    if($(this).attr("data-color")=="R1"){
        $(".list-catalog").css("background-color","rgba(250,245,235,1)");
        $(".list-catalog").css("color","#000");
        $(".triangle").css("border-bottom-color","rgba(250,245,235,1)");
        $("body").css("background-color","rgba(250,245,235,1)");
        $(".fixed-head").css("background-color","rgba(250,245,235,1)");
        $("#top").css("color","#000");
        $("#setting").attr("data-localColor","R1");
        $("#mulu-btn").attr("data-black","R1");
        $(this).addClass("red-circle").siblings().removeClass("red-circle")
    }else if($(this).attr("data-color")=="R2"){
        $(".list-catalog").css("background-color","rgba(245,234,204,1)");
        $(".list-catalog").css("color","#000");
        $(".triangle").css("border-bottom-color","rgba(245,234,204,1)");
        $("body").css("background-color","rgba(245,234,204,1)");
        $(".fixed-head").css("background-color","rgba(245,234,204,1)");
        $("#setting").attr("data-localColor","R2");
        $("#mulu-btn").attr("data-black","R2");
        $("#top").css("color","#000");
        $(this).addClass("red-circle").siblings().removeClass("red-circle")
    }else if($(this).attr("data-color")=="R3"){
        $(".list-catalog").css("background-color","rgba(230,242,230,1)");
        $(".list-catalog").css("color","#000");
        $(".triangle").css("border-bottom-color","rgba(230,242,230,1)");
        $("body").css("background-color","rgba(230,242,230,1)");
        $(".fixed-head").css("background-color","rgba(230,242,230,1)");
        $("#setting").attr("data-localColor","R3");
        $("#mulu-btn").attr("data-black","R3");
        $("#top").css("color","#000");
        $(this).addClass("red-circle").siblings().removeClass("red-circle")
    }else if($(this).attr("data-color")=="R4"){
        $(".list-catalog").css("background-color","rgba(228,241,245,1)");
        $(".list-catalog").css("color","#000");
        $(".triangle").css("border-bottom-color","rgba(228,241,245,1)");
        $("body").css("background-color","rgba(228,241,245,1)");
        $(".fixed-head").css("background-color","rgba(228,241,245,1)");
        $("#setting").attr("data-localColor","R4");
        $("#mulu-btn").attr("data-black","R4");
        $("#top").css("color","#000");
        $(this).addClass("red-circle").siblings().removeClass("red-circle")
    }else if($(this).attr("data-color")=="R5"){
        $(".list-catalog").css("background-color","rgba(245,228,228,1)");
        $(".list-catalog").css("color","#000");
        $(".triangle").css("border-bottom-color","rgba(245,228,228,1)");
        $("body").css("background-color","rgba(245,228,228,1)");
        $(".fixed-head").css("background-color","rgba(245,228,228,1)");
        $("#setting").attr("data-localColor","R5");
        $("#mulu-btn").attr("data-black","R5");
        $("#top").css("color","#000");
        $(this).addClass("red-circle").siblings().removeClass("red-circle")
    }else if($(this).attr("data-color")=="R6"){
        $(".list-catalog").css("background-color","rgba(224,224,224,1)");
        $(".list-catalog").css("color","#000");
        $(".triangle").css("border-bottom-color","rgba(224,224,224,1)");
        $("body").css("background-color","rgba(224,224,224,1)");
        $(".fixed-head").css("background-color","rgba(224,224,224,1)");
        $("#setting").attr("data-localColor","R6");
        $("#mulu-btn").attr("data-black","R6");
        $("#top").css("color","#000");
        $(this).addClass("red-circle").siblings().removeClass("red-circle")
    }
    $("#night-btn").removeClass("check");
    var color = $("#setting").attr("data-localColor");
    var black = $("#mulu-btn").attr("data-black");
    localStorage.a_color =JSON.stringify(color);
    localStorage.a_black =JSON.stringify(black);
});
$(".set-backco a").on("click",function() {
    var font = $("#text").css("font-size");
    var font_num = font.split("px");
    font_num.pop(0,1);
    var font_num_add =parseInt(font_num[0]);
    if($(this).attr("data-font")=="default"){
        $("#text").css("font-size","20px");
    }else if($(this).attr("data-font")=="minus"){
        if(font_num_add- 2 > 9){
            var font_px_1 = (font_num_add - 2) +"px";
            $("#text").css("font-size",font_px_1);
        }
    }
    else if($(this).attr("data-font")=="plus"){
        if(font_num_add+ 2 < 37){
            var font_px_2 = (font_num_add + 2) +"px";
            $("#text").css("font-size",font_px_2);
        }
    }
    var fontSize = $("#text").css("font-size");
    localStorage.a_fontSize =JSON.stringify(fontSize);
});
$(".set-linehi a").on("click",function() {
    if($(this).attr("data-line")=="li-2"){
        $("#text p").css("line-height","1.9rem");
        $(this).addClass("red-line").siblings().removeClass("red-line")
    }else if($(this).attr("data-line")=="li-1"){
        $("#text p").css("line-height","1.4rem");
        $(this).addClass("red-line").siblings().removeClass("red-line")
    }
    else if($(this).attr("data-line")=="li-3"){
        $("#text p").css("line-height","2.5rem");
        $(this).addClass("red-line").siblings().removeClass("red-line")
    }
    var lineHeight = $("#text p").css("line-height");
    localStorage.a_lineHeight =JSON.stringify(lineHeight);
});
function checkColor(){
    var saveColor = $("#setting").attr("data-localColor");
    var saveBlack =  $("#mulu-btn").attr("data-black");
        if(saveColor=="R1"&&saveBlack=="R1"){
            $(".list-catalog").css("background-color","rgba(250,245,235,1)");
            $(".list-catalog").css("color","#000");
            $(".triangle").css("border-bottom-color","rgba(250,245,235,1)");
            $("body").css("background-color","rgba(250,245,235,1)");
            $(".fixed-head").css("background-color","rgba(250,245,235,1)");
            $("#top").css("color","#000");
        }else if(saveColor=="R2"&&saveBlack=="R2"){
            $(".list-catalog").css("background-color","rgba(245,234,204,1)");
            $(".list-catalog").css("color","#000");
            $(".triangle").css("border-bottom-color","rgba(245,234,204,1)");
            $("body").css("background-color","rgba(245,234,204,1)");
            $(".fixed-head").css("background-color","rgba(245,234,204,1)");
            $("#top").css("color","#000");
        }else if(saveColor=="R3"&&saveBlack=="R3"){
            $(".list-catalog").css("background-color","rgba(230,242,230,1)");
            $(".list-catalog").css("color","#000");
            $(".triangle").css("border-bottom-color","rgba(230,242,230,1)");
            $("body").css("background-color","rgba(230,242,230,1)");
            $(".fixed-head").css("background-color","rgba(230,242,230,1)");
            $("#top").css("color","#000");
        }else if(saveColor=="R4"&&saveBlack=="R4"){
            $(".list-catalog").css("background-color","rgba(228,241,245,1)");
            $(".list-catalog").css("color","#000");
            $(".triangle").css("border-bottom-color","rgba(228,241,245,1)");
            $("body").css("background-color","rgba(228,241,245,1)");
            $(".fixed-head").css("background-color","rgba(228,241,245,1)");
            $("#top").css("color","#000");
        }else if(saveColor=="R5"&&saveBlack=="R5"){
            $(".list-catalog").css("background-color","rgba(245,228,228,1)");
            $(".list-catalog").css("color","#000");
            $(".triangle").css("border-bottom-color","rgba(245,228,228,1)");
            $("body").css("background-color","rgba(245,228,228,1)");
            $(".fixed-head").css("background-color","rgba(245,228,228,1)");
            $("#top").css("color","#000");
        }else if(saveColor=="R6"&&saveBlack=="R6"){
            $(".list-catalog").css("background-color","rgba(224,224,224,1)");
            $(".list-catalog").css("color","#000");
            $(".triangle").css("border-bottom-color","rgba(224,224,224,1)");
            $("body").css("background-color","rgba(224,224,224,1)");
            $(".fixed-head").css("background-color","rgba(224,224,224,1)");
            $("#top").css("color","#000");
        }else if(saveColor=="R7"){
            $(".list-catalog").css("background-color","#1b1b1b");
            $(".fixed-head").css("background-color","#1b1b1b");
            $(".list-catalog").css("color","#d5d5d5");
            $(".triangle").css("border-bottom-color","#1b1b1b");
            $("body").css("background-color","#1b1b1b");
            $("#top").css("color","#d5d5d5");
        }
}

})